package com.greensam.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import javax.sql.DataSource;
@Slf4j
@SpringBootApplication(scanBasePackages = "com.greensam.api")
public class ApiApplication implements CommandLineRunner {

    @Autowired
    private DataSource dataSource;

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        try {
            String db = dataSource.getConnection().getMetaData().getURL();
            log.info("当前连接的数据库地址：{}", db);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
